/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.dinner.web.type;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.dinner.entity.type.ResDinnerType;
import com.thinkgem.jeesite.modules.dinner.service.type.ResDinnerTypeService;

/**
 * 餐别管理Controller
 * @author dai
 * @version 2018-11-18
 */
@Controller
@RequestMapping(value = "${adminPath}/dinner/type/resDinnerType")
public class ResDinnerTypeController extends BaseController {

	@Autowired
	private ResDinnerTypeService resDinnerTypeService;
	
	@ModelAttribute
	public ResDinnerType get(@RequestParam(required=false) String id) {
		ResDinnerType entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = resDinnerTypeService.get(id);
		}
		if (entity == null){
			entity = new ResDinnerType();
		}
		return entity;
	}
	
	@RequiresPermissions("dinner:type:resDinnerType:view")
	@RequestMapping(value = {"list", ""})
	public String list(ResDinnerType resDinnerType, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<ResDinnerType> page = resDinnerTypeService.findPage(new Page<ResDinnerType>(request, response), resDinnerType); 
		model.addAttribute("page", page);
		return "modules/dinner/type/resDinnerTypeList";
	}

	@RequiresPermissions("dinner:type:resDinnerType:view")
	@RequestMapping(value = "form")
	public String form(ResDinnerType resDinnerType, Model model) {
		model.addAttribute("resDinnerType", resDinnerType);
		return "modules/dinner/type/resDinnerTypeForm";
	}

	@RequiresPermissions("dinner:type:resDinnerType:edit")
	@RequestMapping(value = "save")
	public String save(ResDinnerType resDinnerType, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, resDinnerType)){
			return form(resDinnerType, model);
		}
		resDinnerTypeService.save(resDinnerType);
		addMessage(redirectAttributes, "保存餐别信息成功");
		return "redirect:"+Global.getAdminPath()+"/dinner/type/resDinnerType/?repage";
	}
	
	@RequiresPermissions("dinner:type:resDinnerType:edit")
	@RequestMapping(value = "delete")
	public String delete(ResDinnerType resDinnerType, RedirectAttributes redirectAttributes) {
		resDinnerTypeService.delete(resDinnerType);
		addMessage(redirectAttributes, "删除餐别信息成功");
		return "redirect:"+Global.getAdminPath()+"/dinner/type/resDinnerType/?repage";
	}

}